<?php

include_once '../../LMSModel/LMSBookRequestModel/LMSBookRequestModel.php';

class Date
{	
	public function getCurrentDay()
	{
		return date('j');
	}
	
	public function getCurrentMonth()
	{
		return date('n');
	}
	
	public function getCurrentYear()
	{
		return date('Y');
	}
	
	public function getTotalNumberOfDays()
	{
		return date('t');
	}
}

class LMSBookIssueController
{
	private $issueDate;
	private $returnDate;
	/** method or function name
	* description
	* parameters 
	* return type
	*/
	function __construct()
	{
		//initiazation can be done
		
	}
	
	function updateBookRequestModel()
	{
		$this->issueDate  = $this->getIssueDate();
		echo $this->issueDate;
		$this->returnDate = $this->getReturnDate();
		echo $this->returnDate;
		$BookRequestModelObject = new LMSBookRequestModel();
		$BookRequestModelObject->updateBookRequestModel($this->issueDate,$this->returnDate,$_REQUEST['BookID']);
	}
	
	function getIssueDate()
	{
		$currentDate = new Date();
		
		$day       = $currentDate->getCurrentDay();
		$month     = $currentDate->getCurrentMonth();
		$year      = $currentDate->getCurrentYear();
		$totalDays = $currentDate->getTotalNumberOfDays();
			
		return $day.':'.$month.':'.$year;
	}
	
	function getReturnDate()
	{
		$currentDate = new Date();
		
		$day       = $currentDate->getCurrentDay();
		$month     = $currentDate->getCurrentMonth();
		$year      = $currentDate->getCurrentYear();
		$totalDays = $currentDate->getTotalNumberOfDays();

			
		$A_returnDay = ($day + 7 > $totalDays) ? 7 -($totalDays - $day): $day + 7;
		$A_returnMonth = ($day > $A_returnDay) ? ($month + 1) : $month;
		$A_returnYear  = ($A_returnMonth > 12) ? ($year +1) : $year;
		$A_returnMonth = ($A_returnMonth > 12) ? 1 : $A_returnMonth;
			
		return $A_returnDay.':'.$A_returnMonth.':'.$A_returnYear;
			
/*			$returnDay = 8;
			$returnMonth = 4;
			$returnYear  = 2014;
			
			$totalDays = array(1=>31,2=>28,3=>31,4=>30,5=>31,6=>30,7=>31,8=>31,9=>30,10=>31,11=>30,12=>31);
			
			if(($A_returnDay <= $returnDay) && ($A_returnMonth == $returnMonth) && ($A_returnYear == $returnYear))
			{
				$days = 0;
			}
			else if (($A_returnMonth == $returnMonth) && ($A_returnYear == $returnYear))
			{
				$days = $returnDay - $A_returnDay;
			}
			else if (($A_returnYear == $returnYear))
			{
				$days = ($totalDays[$A_returnMonth]-$A_returnDay)+$returnDay;
				for($i=$A_returnMonth+1;$i<$month;$i++)
				{
					if ($returnYear%4 == 0)
					{
						$totalDays[2] = $totalDays[2] +1;
					}
					$days = $days + $totalDays[$i];
				}
			}
			else
			{
				$days = ($totalDays[$A_returnMonth]-$A_returnDay)+$returnDay;
				for($i=$A_returnMonth+1 ; $i<=12 ; $i++)
				{
					if ($returnYear%4 == 0)
					{
						$totalDays[1] = $totalDays[1] +1;
					}
					$days = $days + $totalDays[$i];
				}
				for($i=1 ; $i<$returnMonth ; $i++)
				{
					$days = $days + $totalDays[$i];
				}
				$totalYears = $returnYear - $A_returnYear -1;
				$days = $totalYears*365;
				for($i = $A_returnYear+1 ; $i<$returnYear ;$i++)
				{
					if ($returnYear%4 == 0)
					{
						$days = $days + 1;
					}
				}
			}
			echo "Days : ".$days;
*/

	}
}

$BookRequestControllerObject = new LMSBookIssueController();
$BookRequestControllerObject->updateBookRequestModel();